import java.util.HashSet;

/**
 * @author tmh
 * @date 2024/9/20 17:13
 * @description
 */
public class T3无重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
        //使用双指针
        int left = 0, right = 0;
        int maxLen = 0;
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            while (set.contains(c)) {
                set.remove(s.charAt(left++));
            }
            set.add(c);
            int len = right - left + 1;
            maxLen = Math.max(len, maxLen);
            right++;
        }
        return maxLen;
    }

}
